$(function () {
    getUserinfo();

    $('.exte').on('click', function () {
        layer.confirm('确定退出登录？', { icon: 3, title: '提示' }, function (index) {
            //do something
            localStorage.removeItem('token');
            location.href = "/login.html";
            layer.close(index);
        });
    })
})
// 获取用户信息
function getUserinfo() {
    $.ajax({
        type: "get",
        url: "/my/userinfo",
        // headers: { Authorization: localStorage.getItem('token') || '' },
        success: function (response) {
            console.log(response);
            console.log(response.message);
            if (response.status != 0) {
                return
                // return layer.msg(response.message, { icon: 5 })
            }
            getuserPhoto(response.data);
        }
        // complete: function (res) {
        //     // console.log(res);
        //     if (res.responseJSON.status == 1 && res.responseJSON.message == '身份认证失败！') {
        //         localStorage.removeItem('token');
        //         location.href = "/login.html";
        //     }


        // }
    });
}
// 渲染用户信息
function getuserPhoto(data) {
    // 获取用户名称
    let name = data.nickname || data.username;
    $('#welcome').html('欢迎' + name);
    if (data.user_pic) {
        // 渲染图片头像
        $('.layui-nav-img').attr('src', data.user_pic).show();
        $('.text-photo').hide();
    } else {
        // 渲染文字头像
        $('.text-photo').html(name[0].toUpperCase()).show();
        $('.layui-nav-img').hide();
    }
}
